<?php

/**
 * Note I wouldn't use php for long polling as apache will soon run out of threads.
 */

set_time_limit(0);

$results = false;
$loops = 0;

while(true){

	$contents = file_get_contents('results.txt');

	$newresults = explode(PHP_EOL, $contents);

	if(!$results){

		$results = $newresults;
		
	} else {

		if($results !== $newresults || $loops == 20){

			echo json_encode(array('results' => $newresults));
			exit(0);

		}

		sleep(2);
		
	}

	$loops++;


}